package net.ib.mtalk.ui.attachment.vcalendar;

import java.util.List;

import net.ib.mtalk.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class VCalendarListAdapter extends BaseAdapter {

    private VCalendarListActivity mContext;
	private LayoutInflater mInflater;
	private List<VCalendarList> items;
//	private boolean isNew = true;
	
	public VCalendarListAdapter(VCalendarListActivity context, List<VCalendarList> items){
		mContext = context;
		mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.items = items;
	}
	
//	@SuppressWarnings("static-access")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		
		if(convertView == null){
//			convertView = mInflater.inflate(R.layout.item_calendar, null);
			convertView = (LinearLayout)mInflater.inflate(R.layout.item_list_multimedia_vcalendar, parent, false);
			
			holder = new ViewHolder((LinearLayout)convertView);
		} else {
//			isNew = false;
			holder = (ViewHolder)convertView.getTag();
		}
//		mContext.updateCheckView(holder.calendarLinearLayout, items.get(position));
//		mContext.updateDateTextView(holder.dateText, items.get(position));
		mContext.updateTitleTextView(holder.titleText, items.get(position));
		mContext.updateSubTitleTextView(holder.subtitleText, items.get(position));
		
//		holder.itemBox.setOnClickListener(mContext);
//		holder.itemBox.setFocusable(false);
//		holder.calendarLinearLayout.setOnClickListener(mContext);
//		holder.calendarLinearLayout.setSelected(false);
//		holder.calendarLinearLayout.setClickable(true);
//		holder.calendarLinearLayout.setFocusable(false);		
//		holder.calendarLinearLayout.
		
		convertView.setTag(holder);
		return convertView;
	}
	
	private static class ViewHolder{
//		TextView dateText;
		TextView titleText;
		TextView subtitleText;
//		ImageView itemBox;
		LinearLayout calendarLinearLayout;
		
//		LinearLayout item;
		
		ViewHolder(LinearLayout item){
			calendarLinearLayout = (LinearLayout)item.findViewById(R.id.calendar_list_layout);
//			itemBox = (ImageView)item.findViewById(R.id.calendar_check);
//			dateText = (TextView)item.findViewById(R.id.calendar_date_text);
			titleText = (TextView)item.findViewById(R.id.calendar_title_text);
			subtitleText = (TextView)item.findViewById(R.id.calendar_subtitle_text);
//			this.item = item;
		}
	}
	
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}
